import 'package:flutter/material.dart';
import 'package:flutter_app/app/models/movie.dart';
import 'package:nylo_framework/nylo_framework.dart';
import 'package:flutter_app/resources/widgets/image.dart';

class Cover extends StatefulWidget {
  final MoviesList movie;
  final Function(MoviesList movie)? onClick; // 接收点击回调

  const Cover({super.key, required this.movie, this.onClick});

  @override
  createState() => _CoverState();
}

class _CoverState extends NyState<Cover> {
  @override
  get init => () {};

  @override
  Widget view(BuildContext context) {
    return GestureDetector(
      onTap: () {
        if (widget.onClick != null) {
          widget.onClick!(widget.movie);
        }
      },
      child: Row(
        spacing: 10,
        children: [
          Container(
            width: 100,
            child: ClipRRect(
              borderRadius: BorderRadius.circular(4), // 圆角半径
              child: ImageWidget(
                imageUrl: widget.movie.vodPic!,
              ),
            ),
          ),
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                widget.movie.vodName ?? "",
                style: TextStyle(
                  fontSize: 16,
                  fontWeight: FontWeight.bold,
                ),
              ),
              // 修复后的分类标签部分
              if (widget.movie.vodClass != null &&
                  widget.movie.vodClass!.isNotEmpty)
                Wrap(
                  spacing: 8, // 标签之间的水平间距
                  runSpacing: 4, // 行间距
                  children: widget.movie.vodClass!
                      .split(",")
                      .map((tag) => Container(
                            padding: EdgeInsets.all(4),
                            decoration: BoxDecoration(
                              color: Colors.grey[50],
                              borderRadius: BorderRadius.all(
                                Radius.circular(8),
                              ),
                            ),
                            child: Text(
                              tag.trim(),
                              style: TextStyle(
                                fontSize: 12,
                              ),
                            ),
                          ))
                      .toList(),
                ),
            ],
          ),
        ],
      ),
    );
  }
}
